package heima3_2.cn.osc.ui.main_fragment.DynamicFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.oschina.app.R;

import java.util.ArrayList;
import java.util.List;

import heima3_2.cn.osc.base.BaseFragment;
import heima3_2.cn.osc.constant.ResultState;
import heima3_2.cn.osc.ui.adapter.TabAdapter;

/**
 * Created by 超能浣熊 on 2017/1/13.
 */

public class DynamicMainFragment extends BaseFragment {

    public static final String[] tabTitles = {"最新动弹", "热门动弹", "我的动弹"};
    private View view;
    private TabLayout tab;
    private ViewPager viewpager;
    private TabAdapter adapter;
    private String mParam1;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString("tab_fragment1");
        }
    }

    @Override
    protected ResultState onLoadSubData() {
        return ResultState.LOAD_SUCCESS;
    }

    @Override
    protected View onCreateSubSuccessView(LayoutInflater inflater, ViewGroup container) {
        view=inflater.inflate(R.layout.dynamic_main,container,false);
        iniView();
        iniData();
        return view;
    }



    private void iniView(){
        tab = (TabLayout) view.findViewById(R.id.tab_dynamic);
        viewpager = (ViewPager) view.findViewById(R.id.vp_dynamic);
    }

    private void iniData(){
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < tabTitles.length; i++) {
            fragments.add(DynamicFragment.newInstance(i + 1));
        }
        adapter = new TabAdapter(getFragmentManager(),fragments,tabTitles);
        viewpager.setAdapter(adapter);
        tab.setupWithViewPager(viewpager);
        tab.setTabMode(TabLayout.MODE_SCROLLABLE);
        tab.setTabGravity(TabLayout.GRAVITY_FILL);
        tab.setTabMode(TabLayout.MODE_FIXED);
    }
}
